package com.teocom.vet;

import java.util.Properties;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;

public class HibernateUtil {
	private static final SessionFactory factory;
	
	static {
		
		Configuration configuration = new Configuration();
		configuration.addProperties(getProperties());
		configuration.addAnnotatedClass(Owner.class);
		configuration.addAnnotatedClass(Person.class);
		configuration.addAnnotatedClass(Pet.class);
		configuration.addAnnotatedClass(Specialty.class);
		configuration.addAnnotatedClass(Vet.class);
		configuration.addAnnotatedClass(Visit.class);
		
		factory = configuration.buildSessionFactory();
	}
	
	private HibernateUtil () {
//		Helper
	}
	
	public static SessionFactory getSessionFactory() {
		return factory;
	}
	
	private static Properties getProperties() {
		Properties properties = new Properties();
//		properties.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
		properties.setProperty(Environment.URL, "jdbc:mysql://localhost:3306/vet");
		properties.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
		properties.setProperty(Environment.USER, "root");
		properties.setProperty(Environment.PASS, "globant");
		properties.setProperty(Environment.SHOW_SQL, "true");
		properties.setProperty(Environment.FORMAT_SQL, "true");
		properties.setProperty(Environment.HBM2DDL_AUTO, "create");
		return properties;
	}
}